package org.ding.infra.repository.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.ding.api.dto.InsertUserDTO;
import org.ding.domain.entity.Score;
import org.ding.domain.entity.Student;
import org.ding.domain.Repository.StudentRepository;
import org.ding.infra.mapper.StudentMapper;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ding
 * @description 针对表【student】的数据库操作Service实现
 * @createDate 2023-03-23 20:05:57
 */
@Service
public class StudentRepositoryImpl extends ServiceImpl<StudentMapper, Student>
        implements StudentRepository {

    @Override
    public List<Student> getAllStudent() {
        return baseMapper.getAllStudent();
    }

    @Override
    public Boolean updateStudent(String id, String name) {
        return baseMapper.updateStudent(id, name);
    }

    @Override
    public Boolean deleteStudentById(String id) {
        return baseMapper.deleteUserById(id);
    }

    @Override
    public Boolean insertStudent(InsertUserDTO dto) {
        Student build = Student.builder()
                .sId(dto.getId())
                .sName(dto.getName())
                .sBirth(dto.getBirthday())
                .sSex(dto.getSex()).build();
        return baseMapper.insertStudent(build);
    }

    @Override
    public List<Score> getScoreByUserName(String name) {
        return baseMapper.getScoreByUserName(name);
    }

    @Override
    public List<Student> listStudent(ArrayList<String> x) {
        return baseMapper.getStudentByIds(x);
    }

    @Override
    public Student testIf(String name) {
        return baseMapper.testIf(name);
    }

    @Override
    public List<Student> getStudentByTeacherId(String id) {
        return baseMapper.getStudentByTeacherId(id);
    }

    @Override
    public Boolean multiInsert(List<InsertUserDTO> list) {
        List<Student> collect = list.stream().map(x -> Student.builder()
                .sId(x.getId())
                .sName(x.getName())
                .sBirth(x.getBirthday())
                .sSex(x.getSex()).build()).collect(Collectors.toList());

        return baseMapper.multiInsert(collect);
    }

}




